package net.dodoman.ibatis;

import java.io.IOException;
import java.io.Reader;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class SqlMapConf {
	// 初始化SqlMapClient
	private static SqlMapClient sqlmapclient;
	static {
		// 定义ibatis配置文件的路径
		String resource = "net/dodoman/ibatis/maps/SqlMapConfig.xml";
		try {
			// 读取ibatis配置文件
			Reader reader = Resources.getResourceAsReader(resource);
			// 通过SqlMapClientBuilder创建SqlMapClient
			sqlmapclient = SqlMapClientBuilder.buildSqlMapClient(reader);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			System.err.println("找不到SqlMapConfig.xml文件~~");
		}
	}

	public static SqlMapClient getInstance() {
		// 返回sqlmapclient,SqlMapClient是ibatis的核心主建，提供数据操作的基础平台
		return sqlmapclient;
	}
	/**
	 * SqlMapClient的另一种创建方式 XmlSqlMapClientBuilder xmlbuilder=new
	 * XmlSqlMapClientBuilder(); SqlMapClient
	 * sqlmapclient=xmlbuilder.builderSqlMap(reader);
	 * XmlSqlMapClientBuilder是ibatis2.0之后版本新引入的组件，用以取代1.X版本中的
	 * XmlSqlMapBuilder，其作用就是创建SqlMapClient。
	 */
}
